package h0805;

import java.util.Scanner;

/**
 * @author 不知名帅哥
 * @version 1.0
 * @description N进制减法
 * @date 2024/8/5 8:56
 */
public class NRadixSubtraction {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int radix = sc.nextInt(); //进制
        String minuend = sc.next();
        String subtractor = sc.next();
        System.out.println(getRes(radix, minuend, subtractor));
    }

    private static String getRes(int radix, String minuend, String subtractor) {
        if (minuend == null || subtractor == null || minuend.isEmpty() || subtractor.isEmpty()) {
            return "-1";
        }
        if (minuend.charAt(0) == '0' || subtractor.charAt(0) == '0') {
            return "-1";
        }
//        int minu = Integer.parseInt(minuend);
//        int sub = Integer.parseInt(subtractor);
        int minu = Integer.parseInt(minuend, radix);
        int sub = Integer.parseInt(subtractor,radix);
        int ans = minu - sub;

        String ansStr=Integer.toString(ans,radix);
        if (ans>=0){
            return "0"+" "+ansStr;
        }else {
            return "1"+" "+ansStr;
        }
    }
}
